//
//  TouchView.m
//  UI29_Block
//
//  Created by Scott on 16/1/21.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "TouchView.h"

@interface TouchView ()

@property (strong, nonatomic) IBOutlet UIView *view;

@property (nonatomic, copy) void (^block)(TouchView *);

@property (nonatomic, copy) void (^deleBtnHandle)(UIButton *);

@property (nonatomic, copy) void (^editBtnHandle)(UIButton *);

@end

@implementation TouchView

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    
    self = [super initWithCoder:aDecoder];
    if (self) {
     
        [[NSBundle mainBundle] loadNibNamed:@"TouchView" owner:self options:nil];
        
        self.view.frame = self.bounds;
        [self addSubview:self.view];

    }
    return self;
}


- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    // 点击之后, 调用block
    
    self.block(self);
}

/** 实现带block参数的方法. */
- (void)viewDidClick:(void (^)(TouchView *))block {
    
    self.block = block;
}



- (void)buttonHandle:(void (^)(UIButton *))block {
    
    self.deleBtnHandle = block;
    
}


- (void)editBtnHandle:(void (^)(UIButton *))block1 deleBtnHandle:(void (^)(UIButton *))block2 {
    
    self.editBtnHandle = block1;
    
    self.deleBtnHandle = block2;
    
    
}

/** 点击删除button. */
- (IBAction)handleButtonAction:(id)sender {
    
    self.deleBtnHandle((UIButton *)sender);
    
}

/** 点击编辑button. */
- (IBAction)handleEditButton:(id)sender {
    
    self.editBtnHandle((UIButton *)sender);
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
